#!/bin/sh

LIBRENMS_DIR=$(dirname "$(readlink -f "$0/..")")
cd "$LIBRENMS_DIR" || exit

if [ $# -eq 0 ]; then
    echo "Error: You must specify a PR number to apply a patch"
    exit 1
fi

for pr in "$@"
    do
        case $pr in
        ''|*[!0-9]*) echo "Error: You must specify a PR number to apply a patch" ;;
        5926) echo "Error: 5926 is just an example PR number. Please specify the actual PR number you want to apply." ;;
        *) curl -s https://patch-diff.githubusercontent.com/raw/librenms/librenms/pull/"${pr}".diff | git apply --exclude=*.png -v && php artisan optimize:clear ;;
    esac
done

